package br.com.rookgraph;


public class BrancheReduceDepuration extends BranchReduce {

	private int interecaoExt;
	private int interecaoInt;

	public BrancheReduceDepuration(Graph original, Graph tree, boolean useIR) {
		super(original, tree, useIR);
		this.interecaoExt = 0;
		this.interecaoInt = 0;
	}

	@Override
	public Graph execute() {

		System.out.println("\n GRAFO ORIGINAL \n");
		getOriginal().showMatix();

		System.out.println("\n TREE INICIAL \n");
		getTree().showMatix();

		Graph treefinal = super.execute();
		System.out.println("\n TREE FINAL \n");
		treefinal.showMatix();

		return treefinal;
	}

	@Override
	public Edge[] createCuttingList(){
		interecaoInt = 0;
		Edge[] listCut = super.createCuttingList();
		System.out.println("\n");
		System.out.println("\n\t Iteração externa > "+ (++interecaoExt));
		System.out.println("\t\t Lista de corte: ");
		showEdges(listCut, false);
		return listCut;
	}

	@Override
	public Edge selectCutEdge(final Edge[] listCut) {
		Edge cutEdge = super.selectCutEdge(listCut);
		System.out.println("\n\t\t\t Iteração interna > "+ (++interecaoInt));
		System.out.print("\t\t\t\t Aresta de Corte: ");
		System.out.println(""+cutEdge);
		return cutEdge;
	}

	@Override
	public Edge[] createReplacementListToCuttingEdge(final Edge arestaCut){
		Edge[] repList = super.createReplacementListToCuttingEdge(arestaCut);
		System.out.println("\t\t\t\t Candidatas a Rep.: ");
		showEdges(repList, true);
		return repList;
	}

	@Override
	public Edge selectEdgeFromReplamentList(final Edge[] listRep, Edge edgeCut) {
		Edge repEdge = super.selectEdgeFromReplamentList(listRep, edgeCut);
		System.out.print("\t\t\t\t Replace: ");
		System.out.println("   "+repEdge);
		return repEdge;
	}

	@Override
	public boolean isTreeBest(Graph graphBest) {
		boolean treeBest = super.isTreeBest(graphBest);
		System.out.println("\t\t\t\tA arvore atual é possui menos braches que a melhor? " + treeBest);
		return treeBest;
	}

	public void showEdges(Edge[] result, boolean nivel2) {
		String ident = nivel2 ? "\t\t\t\t\t" : "\t\t\t";
		for (Edge edge : result) {
			System.out.println(ident+edge);
		}
	}

}
